﻿package com.tvein.sanguo.swc.action.role
{
	//flash
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	//A3D
	//custom
	import com.tvein.sanguo.swc.common.OverLay;
	import com.tvein.sanguo.swc.common.SwcEvent;
	import com.tvein.sanguo.swc.common.MP3Click;
//
	public class RoleArmy extends MovieClip
	{
		public static const NAME:String = "Role-Army";

		private var effectVol:int = 100;
		private var overLay:OverLay;
		
		public function RoleArmy()
		{
			stage?init(null):addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(evt:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE , init);
			addEventListener(Event.REMOVED_FROM_STAGE, _onRemoved);
			stage.addEventListener(Event.RESIZE, _resizeUI);
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			overLay = new OverLay();			
			this.addChild(overLay);
			this.setChildIndex(overLay, 0);
			
			btnClose.addEventListener(MouseEvent.CLICK, onClick);
			btnDetail.addEventListener(MouseEvent.CLICK, onClick);
			btnGoods.addEventListener(MouseEvent.CLICK, onClick);
			btnItem.addEventListener(MouseEvent.CLICK, onClick);
			btnSkill.addEventListener(MouseEvent.CLICK, onClick);
			
			mcFrame.reSize(600, 450);
			
			_resizeUI();
		}
		
		public function console(Type:String, params:Object):void
		{
			switch (Type)
			{
				case "setEffect":
					effectVol = params.Volume;
					break;
				case "setData":
					setData(params);
					break;
			}
		}

		private function setData(params:Object):void
		{
			
		}

		private function _onRemoved(evt:Event):void
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, _onRemoved);
			stage.removeEventListener(Event.RESIZE, _resizeUI);
			
			btnClose.removeEventListener(MouseEvent.CLICK, onClick);
			btnDetail.removeEventListener(MouseEvent.CLICK, onClick);
			btnGoods.removeEventListener(MouseEvent.CLICK, onClick);
			btnItem.removeEventListener(MouseEvent.CLICK, onClick);
			btnSkill.removeEventListener(MouseEvent.CLICK, onClick);
		}

		private function _resizeUI(evt:Event = null):void
		{
			overLay.x = overLay.y = overLay.width = overLay.height = 0;
			
			this.x = (stage.stageWidth - this.width) * .5
			
			if ((stage.stageHeight - this.height) > 150)
			{
				this.y = (stage.stageHeight - this.height) * .3;
			}
			else
			{
				this.y = 45;
			}
			
			overLay.x = 0 - this.x;
			overLay.y = 0 - this.y;
			overLay.width = stage.stageWidth;
			overLay.height = stage.stageHeight;
		}

		private function onClick(evt:MouseEvent):void
		{
			var soundEffect:MP3Click = new MP3Click();
			soundEffect.playback(effectVol * .01);
			
			switch(evt.target.name)
			{
				case "btnDetail":
					dispatchEvent(new SwcEvent(NAME, ["-roleDetail"]));
					break;
				case "btnGoods":
					dispatchEvent(new SwcEvent(NAME, ["-roleGoods"]));
					break;
				case "btnItem":
					dispatchEvent(new SwcEvent(NAME, ["-roleItem"]));
					break;
				case "btnSkill":
					dispatchEvent(new SwcEvent(NAME, ["-roleSkill"]));
					break;
			}
		}
	}
}